<?php

namespace App\Models\Traits;

use App\Util\LoginUtil;
use Illuminate\Database\Eloquent\Model;

trait HasGroupScope
{
    public static function bootHasGroupScope(): void
    {
//        static::addGlobalScope(new GroupScope);
        static::creating(function(Model $model){
            $group_id = LoginUtil::getGroupId();
            if (!empty($group_id)&& empty(data_get($model, 'group_id'))) {
                $model->setAttribute('group_id', $group_id);
            }
        });
    }
}
